package com.dk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dk.data.Result;
import com.dk.entity.DtContent;
import com.dk.service.IDtContentService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("content")
public class ContentController {
    @Autowired
    private IDtContentService contentService;

    @GetMapping("selectContent")
    @ResponseBody
    @ApiOperation("查询所有的广告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页数", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, paramType = "query")
    })
    public Result selectContent(@RequestParam(defaultValue = "1") Integer pageNum ,
                                @RequestParam(defaultValue = "5") Integer pageSize){
        IPage<DtContent> page = contentService.selectPage(pageNum, pageSize);
        return Result.ok().setData(page);
    }


    @PostMapping("updateContent")
    @ResponseBody
    @ApiOperation("修改广告")
    public Result updateContent(DtContent dtContent){
        contentService.updateContent(dtContent);
        return Result.ok();
    }

    @PostMapping("selectContentBuId")
    @ResponseBody
    @ApiOperation("根据id查询广告")
    public Result selectContentBYId(Long id){
        DtContent dtContent = contentService.selectContentById(id);
        return Result.ok().setData(dtContent);
    }

    @PostMapping("deleteContent")
    @ResponseBody
    @ApiOperation("根据id删除")
    public Result deleteContent(Long id){
        contentService.deleteContentById(id);
        return Result.ok();
    }

}
